package com.dream.dynamic_datasource.dynamic;

import lombok.Data;

/**
 * @description:
 * @author: Luo
 * @create: 2020-08-25 15:13
 */
@Data
public class DynamicDataSourceContextHolder {
    /**
     * 线程级别的私有变量
     */
    private static final ThreadLocal<String> contextHolder  = new ThreadLocal<>();

    public static String getDataSourceRouterKey () {
        return contextHolder .get();
    }

    public static void setDataSourceRouterKey (String dbName) {
        contextHolder .set(dbName);
    }

    /**
     * 设置数据源之前一定要先移除
     */
    public static void removeDataSourceRouterKey () {
        contextHolder .remove();
    }

}
